package weixinkeji.dev.dc.base.food.h.food;

import com.alibaba.fastjson.JSON;
import pz.MyFileSet;
import pz.dc.FilePath;
import sys.wx.ann.hm.H;
import sys.wx.ann.hm.M;
import sys.wx.c.ATR;
import sys.wx.c.components.check.xy.CheckXY;
import sys.wx.c.components.cv.CV;
import sys.wx.components.file.bean.FI;
import sys.wx.components.file.bean.FileConfig;
import sys.wx.components.file.up.FileUpOne;
import sys.wx.m.db.dao.mysql.Dao;
import weixinkeji.dev.dc.base.food.bean.Food;
import weixinkeji.dev.dc.base.scheme.promotions.so.PromotionDaySO;

/**
 *
 * @author IMY
 */
@H("weixinkeji/dev/dc/base/food/file")
public class FoodImgUp {

//演示文件上传。
    @M("/imgUpload")//weixinkeji/dev/dc/base/food/file/imgUpload.imy
    public static String upMyImg(ATR a) {
        String id = CV.getParameter(a.request, "foodID", CheckXY.ID);
        if (null == id) {
            return null;
        }
        //单文件上传
        FileUpOne up = new FileUpOne(new FileConfig(a.request, FilePath.DC_BASE_FOOD_IMG, MyFileSet.getImgFileSet()));
        FI fi = up.upFile();                        //默认只找到排在第一位的文件上传并返回处理结果FI对象
        Food obj = new Food();
        obj.setFood_id(id);
        obj.setFood_img(fi.path_saveName);
        if (!Dao.updateAlloy(obj, "food_img")) {
            fi.isok = false;
        } else {
            new PromotionDaySO().updateFileImg(id, fi.path_saveName);
        }
        a.printOne(JSON.toJSONString(fi));//返回服务端处理结果
        return null;
    }
}
